<template>
  <div class="resume">
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>简历上传</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card class="container">
      <el-form label-width="80px" :model="model">
        <el-form-item label="标题文字">
          <el-input v-model="model.title"> </el-input>
        </el-form-item>
        <el-form-item label="标题文字2">
          <el-input v-model="model.title2"> </el-input>
        </el-form-item>
        <el-form-item label="简历文件">
          <el-upload
            class="resume-upload"
            drag
            :action="baseURL + '/resumeupload'"
            :on-success="afterUpoad"
          >
            <div class="file-name">{{ model.fileName }}</div>
            <div class="el-upload__text">
              拖拽 或<em>点击此处</em> 可上传或更新文件
            </div>
          </el-upload>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="save" class="mt10">保存</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import { reactive, toRefs, onBeforeMount } from "vue";
import { baseURL, putData, getData, postData } from "../../services/http";
export default {
  name: "Resume",
  setup() {
    const state = reactive({
      model: {},
    });
    onBeforeMount(() => {
      getResume();
    });
    const getResume = async () => {
      const { data: res } = await getData("rest/resume");
      if (res.data.length) {
        state.model = res.data[0];
        return;
      }
    };
    const save = () => {
      const id = state.model._id;
      if (id) {
        return putData(`rest/resume/${id}`, state.model, "修改简历信息成功");
      }
      postData("rest/resume", state.model, "保存简历信息成功");
      getResume();
    };
    const afterUpoad = (res) => {
      state.model.fileName = res.originalname;
      state.model.fileUrl = res.path;
    };
    return {
      ...toRefs(state),
      save,
      baseURL,
      afterUpoad,
    };
  },
};
</script>

<style lang="scss">
.resume-upload {
  width: 200px;
  //height: 200px;
  .el-upload {
    height: auto;
  }
}
.resume {
  width: 50%;
  .el-upload {
    height: auto;
  }
  .el-upload-dragger {
    text-align: center;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
  }
  .file-name {
    font-size: 20px;
  }
}
</style>
